Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update resolver to query user by orcid or id #3258

Merged
merged 16 commits into from
Jan 8, 2025
Merged

Conversation

thinknoack
Copy link
Contributor

@thinknoack thinknoack commented Dec 17, 2024

updating the resolver so a user can be queried by orcid or id.

@thinknoack thinknoack requested a review from nellh December 17, 2024 23:56
@thinknoack thinknoack marked this pull request as draft December 17, 2024 23:57
Copy link

codecov bot commented Dec 18, 2024

Codecov Report

Attention: Patch coverage is 87.64368% with 43 lines in your changes missing coverage. Please review.

Project coverage is 46.67%. Comparing base (2d92dda) to head (becde43).
Report is 23 commits behind head on master.

Files with missing lines Patch % Lines
...uro-app/src/scripts/users/components/edit-list.tsx 25.92% 20 Missing ⚠️
...ges/openneuro-server/src/graphql/resolvers/user.ts 0.00% 12 Missing ⚠️
.../src/scripts/users/components/editable-content.tsx 86.44% 8 Missing ⚠️
...o-app/src/scripts/users/components/edit-string.tsx 90.00% 2 Missing ⚠️
...ges/openneuro-app/src/scripts/users/user-query.tsx 97.77% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3258      +/-   ##
==========================================
- Coverage   46.68%   46.67%   -0.01%     
==========================================
  Files         609      609              
  Lines       38701    38734      +33     
  Branches     1225     1232       +7     
==========================================
+ Hits        18068    18080      +12     
- Misses      20438    20459      +21     
  Partials      195      195              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@thinknoack thinknoack marked this pull request as ready for review December 19, 2024 22:23
@thinknoack
Copy link
Contributor Author

thinknoack commented Dec 19, 2024

@nellh - I think I have this as we discussed. I will need some help to write test coverage for this
packages/openneuro-server/src/graphql/resolvers/user.ts what I tried was not working as expected.

also I added the gql user query in the user-query.tsx and I am writing/updating tests for that. I will also need to adjust templates to account for fields that are not required (like avatar). Putting back into draft but would love your feedback.

@thinknoack thinknoack marked this pull request as draft December 19, 2024 23:31
@thinknoack thinknoack marked this pull request as ready for review January 7, 2025 19:31
Copy link
Contributor

@nellh nellh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this looks good. The precommit hook didn't get run so the formatting is wrong in some spots. One fix needed for the functionality but it would also be good to fix the formatting.

}

if (isValidOrcid(id)) {
return User.findOne({ "orchid": id }).exec()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return User.findOne({ "orchid": id }).exec()
return User.findOne({ "orcid": id }).exec()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One typo here but another limitation is there's two kinds of user records here:

{
  "provider": "orcid",
  "providerId": "0000-0000..."
}
{
  "provider": "google",
  "orcid": "0000-0000..."
}

This branch needs to find both of these. Once we've migrated Google users to ORCID logins, most users will fall into the first group that won't match here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated typo.

Copy link
Contributor Author

@thinknoack thinknoack Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nellh something like this?

export const user = (obj, { id, key }) => {
  function isValidOrcid(orcid: string): boolean {
    return /^[0-9]{4}-[0-9]{4}-[0-9]{4}-[0-9]{3}[0-9X]$/.test(orcid || "")
  }

  if (isValidOrcid(id)) {
    if (key === 'orcid') {
      return User.findOne({ "orcid": id }).exec(); // Search by orcid if key is 'orcid'
    } else {
      return User.findOne({ "providerId": id }).exec(); // Otherwise, search by providerId
    }
  } else {
    return User.findOne({ "id": id }).exec(); // Search by id if not a valid ORCID
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be a single query, you can use the {$or: [{ "orcid": id }, {"providerId": id}]} operator to check if the id is in either field. No need for a key argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty - that was helpful. I have that added now

@thinknoack thinknoack requested a review from nellh January 8, 2025 00:49
@nellh nellh merged commit 2b3ed14 into master Jan 8, 2025
15 checks passed
@nellh nellh deleted the user-resolver-find-by-orcid branch January 8, 2025 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants